package com.woniuxy.car.commodity.service.core.controller;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.woniuxy.car.commodity.service.core.dto.CommodityCommentTagDto;
import com.woniuxy.car.commodity.service.core.entity.CommodityCommentTag;
import com.woniuxy.car.commodity.service.core.service.ICommodityCommentTagService;
import com.woniuxy.common.api.CommonResult;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author awz
 * @since 2022-03-02
 */
@AllArgsConstructor
@Api(tags = "商品评价标签接口")
@RestController
@RequestMapping("/commodity/commodity-comment-tag")
public class CommodityCommentTagController {

    private ICommodityCommentTagService commodityCommentTagService;

    @PostMapping("/saveOrUpdateCommodityCommentTag")
    public CommonResult<Boolean> saveOrUpdateCommodityCommentTag(@RequestBody CommodityCommentTagDto commodityCommentTagDto){
        CommodityCommentTag commodityCommentTag = new CommodityCommentTag();
        if(ObjectUtil.isNotEmpty(commodityCommentTagDto.getId())){
            commodityCommentTag.setId(commodityCommentTagDto.getId());
        }
        List<String> tags = commodityCommentTagDto.getContent();
        commodityCommentTag.setContent(JSONUtil.toJsonStr(tags));
        boolean success = commodityCommentTagService.saveOrUpdate(commodityCommentTag);
        return CommonResult.success(success);
    }
}
